<template>
  <el-container class="bg-white rounded" :style="{ height: (h + 'px') }">
    <el-header class="image-header">
      <el-button type="primary" size="small" @click="handleOpenCreate">新增图片分类</el-button>
      <el-button type="warning " size="small" @click="handleOpenUpload">上传图片</el-button>

    </el-header>
    <el-container>
      <ImageAside ref="ImageAsideRef" @change="handleAsideChange"></ImageAside>
      <ImageMain ref="imageMainRef"></ImageMain>

    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import ImageAside from '~/components/ImageAside.vue'
import ImageMain from '~/components/ImageMain.vue'

const windowHeight = window.innerHeight || document.body.clientHeight
const h = windowHeight - 64 - 44 - 40

const ImageAsideRef = ref(null)
const handleOpenCreate = () => ImageAsideRef.value.handleCreate()

const imageMainRef = ref(null)
// 拿到当前点击时的分类id
const handleAsideChange = (imageClassId) => {
  imageMainRef.value.loadData(imageClassId)
}

// 通过组件实例,拿到子组件暴露出来的方法
const handleOpenUpload = () => imageMainRef.value.openUploadFile()

</script>

<style scoped>
.image-header {
  border-bottom: 2px solid #eee;
  @apply flex items-center;
}
</style>